package com.zhangji.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

/**
 * @Description: 主启动类
 * @Author: Zhang Ji
 * @Date: 2021/6/23 9:14
 * Created by IntelliJ IDEA.
 */
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient // 服务发现
@EnableCircuitBreaker// Hystrix的熔断器
// ZJTODO: 2021/6/28 引入@EnableCircuitBreaker开启熔断器
public class HystrixDeptProvider_8001 {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDeptProvider_8001.class,args);
    }


    /**
     * @Description: 增加servlet以返回Hystrix Dashboard监控信息，固定写法
     * @return servletRegistrationBean
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet(){
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");
        return servletRegistrationBean;
    }

}
